const { public: { baseURL, appcode, referer } } = useRuntimeConfig()
export default defineEventHandler(async (event) => {
   if (event.node.req.url?.includes('/api')) {
      const { method, url, headers } = event.node.req
      const options: any = new Object()
      delete headers.host
      options.method = method 
      options.headers = { ...headers, appcode, referer }
      if (method === 'POST') options.body = await readBody(event)
      return await $fetch(baseURL + url, options).then((res: any) => {
         if (res.status === 40001) {
            return res
         } else {
            return res 
         }
      }).catch(err => {
         console.log("err", err);
         return {
            status: 500,
            message: '服务端错误',
            data: null
         }
      })
   }
})